package cate.game.role.show.msg;

import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBBlog;
import cate.game.role.Role;
import cate.game.role.show.vehicle.VehicleSkin;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcResult;

@ClientMsg(title = "载具皮肤穿戴 の 请求")
public class VehicleSkinOnReq implements MsgInput {

	@NoteField("载具id")
	public int tid;

	@Override
	public void execute(GameBody game, ClientContext cc) {
		EcResult r =  settle(cc.getRole());
		game.notice.message(cc.getRole(), r, true);
	}

	private EcResult settle(Role role) {
		EcResult r = new EcResult();
		if (tid > 0) {
			VehicleSkin vehicle = role.getShow().vehicle.getItem(tid);
			if (vehicle == null) {
				return r.fail("载具未激活");
			}
			role.getBase().vehicle.read(vehicle);
		}else {
			role.getBase().vehicle.clear();
		}
		role.sendNow(new VehicleSkinOnResp(role));
		return r.success();
	}

	@Override
	public MsgConfig conf() {
		return MsgIdBBlog.VEHICLE_ON_REQ;
	}
}
